<template>
    <div >
      <span v-if="attentionshow === true" class="followed">已关注</span>
      <div v-else><span class="focus" @click.self.stop="attention()">关注问题</span></div>
    </div>
</template>
<script>
import api from '../api'
import utils from '../utils'
export default {
  props: [ 'itematt' ],
  data () {
    return {
      attentionshow: false
    }
  },
  created () {
    if (this.itematt.watchIt === true) {
      this.attentionshow = true
    } else {
      this.attentionshow = false
    }
  },
  methods: {
    // 点击关注
    attention () {
      var timeStamp = String(Number(new Date()))
      var tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
      var params = {
        Tokenuser: tokenval,
        userid: this.$store.state.userID,
        timestamp: timeStamp,
        contentId: this.itematt.id
      }
      api.attentioncontent(params).then(res => {
        console.log(res)
        if (res.status === 200) {
          this.attentionshow = true
        } else {
          this.$vux.toast.show({
            text: res.message,
            type: 'warn',
            width: '4rem'
          })
        }
      })
    }
  }
}
</script>

